﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PetaPoco;
using PmSoft;
using PmSoft.ApplicationContext;
using PmSoft.DBContext;
using PmSoft.Repositories;
using PmSoft.Utilities;

namespace Modules.Project.Repositories
{
    [UseDI(ServiceLifetime.Scoped)]
    public class ProjectSecurityDepositPaymentDetailsRepository : Repository<ProjectSecurityDepositPaymentDetails, DefaultDbContext>
    {
        private readonly ILogger logger;

        public ProjectSecurityDepositPaymentDetailsRepository(DefaultDbContext dbContext, IApplicationContext applicationContext, ILogger<ProjectSecurityDepositPaymentDetailsRepository> logger)
           : base(dbContext, applicationContext)
        {
            this.logger = logger;
        }

        public IPagedList<ProjectSecurityDepositPaymentDetails> GetProjectSecurityDepositRecords(ProjectSecurityDepositPaymentDetailsQuery query, int pageIndex, int pageSize)
        {
            Sql sql = Sql.Builder;
            sql.Select("id")
                .From("project_security_deposit_payment_details");
            if (!string.IsNullOrEmpty(query.Keywords))
                sql.Where("(person_name Like @0 or code Like @0 or code Like @0)", "%" + StringUtility.StripSQLInjection(query.Keywords) + "%");

            if (query.ProjectId.HasValue)
                sql.Where("project_id=@0", query.ProjectId);
            sql.OrderBy("create_time DESC");
            return GetPagingEntities(pageSize, pageIndex, sql);
        }
    }
}